<template>
  <basic-container :btnFlag = true>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <div style="float: left;margin-left: 17px;margin-top: 16px;">
        <span><b style="margin-right: 12px;">规划名称:</b>{{title}}</span>
      </div>
      <div style="float: right;margin-right: 17px;margin-top: 16px;">
        <el-button type="primary" size="mini" @click="addPlanConnection()">发起衔接</el-button>
      </div>
      <div class="card-body">
        <avue-crud :data="levyResultData"
                   :option="tableoption"
                   :page="page"
                   :table-loading="tableLoading"
                   @on-load="getResultList"
                   @size-change="sizeChange"
                   @current-change="currentChange"
                   class="menu-min-height">
          <template slot-scope="scope" slot="menu">
            <div class="menu-title" @click.stop="planConnectionFeedback(scope.row,scope.index)" v-if="scope.row.state=='4'">
              <i class="iconfont iconview icon-primary"></i>
              <p class="menu-title-text">衔接结果</p>
            </div>
          </template>
        </avue-crud>
      </div>
      <!--<el-dialog title="衔接结果" :visible.sync="dialogVisible" width="70%">-->
        <!--<div style="margin-top: -68px">-->
          <!--<bostech-detail :detail-data="detailData"></bostech-detail>-->
        <!--</div>-->
        <!--<span slot="footer" class="dialog-footer">-->
            <!--<el-button @click="dialogVisible = false">关 闭</el-button>-->
          <!--</span>-->
      <!--</el-dialog>-->
      <el-dialog title="衔接结果" :visible.sync="dialogVisible" width="70%">
        <el-form
          label-width="130px"
          :model="projectForm"
          style="padding-right: 30px;"
          ref="projectForm"
        >
          <el-row>
            <el-col :span="11">
              <el-form-item class="form-item-release" label="意见类型 :" prop="hasOpinion">
                <!-- <el-radio v-model="projectForm.hasOpinion" label="0">无意见</el-radio> -->
                <el-radio v-model="projectForm.hasOpinion" label="1">衔接意见</el-radio>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="22">
              <el-form-item class="form-item-release" label="衔接意见 :" prop="opinion">
                <el-input
                  type="textarea"
                  :autosize="{ minRows: 4, maxRows: 4}"
                  placeholder="请输入衔接意见"
                  v-model="projectForm.opinion"
                ></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item class="form-item-release" label="联系人 :" prop="contactName">
                <el-input
                  v-model="projectForm.contactName"
                  placeholder="请输入联系人"
                  style="width: 280px"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="11">
              <el-form-item class="form-item-release" label="联系电话 :" prop="contactNumber">
                <el-input
                  v-model="projectForm.contactNumber"
                  placeholder="请输入联系电话"
                  style="width: 280px"
                >
                </el-input>
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>

        <div style="margin-top: 18px;margin-left: 78px;">
          <p class="" style="float:left;font-weight: 600;margin-bottom: 0px;">附件 ：</p>
          <div v-for="(file,index) in files" :key="index" class="relateddivsubject">
            <el-tooltip class="item" effect="dark" content="下载资料" placement="top-start">
              <el-button class="downbtn" @click="fileDownload(file.fileId,file.fileName)">
                <img src="img/download-blue.png" class="detail-data-img"/><span>下载</span>
              </el-button>
            </el-tooltip>
            <p class="detail-data-file" v-if="file.fileName">{{file.fileName}}</p>
          </div>
          <p class="detail-data-file" v-if="files.length==0">无</p>
        </div>

        <span slot="footer" class="dialog-footer">
            <el-button @click="dialogVisible = false">关 闭</el-button>
        </span>
      </el-dialog>
    </div>
  </basic-container>
</template>
<script>
  import {getLevyFeedbackAllList,levyDelete} from "@/api/subject";
  import {getmaterialCollectionAll,urgentCollection} from "@/api/fileTask";
  import {getfileinfopage} from "@/api/system"
  import {getConnectionList,planConnectionFeedback} from "@/api/make"
  import {opinionTagertList,formOpinion} from "@/api/opinion"
  import {getNotNull,getFileTypeFiles} from '@/views/util';
  export default {
    name: "connectionList",
    created(){
      this.title = this.$route.query.title
    },
    data(){
      return{
        headerData:{
          title:'规划衔接-规划衔接列表'
        },
        levyResultData:[],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        tableoption: {
          page: true,
          menuWidth:140,
          addBtn: false,
          editBtn: false,
          addRowBtn: false,
          indexLabel: "序号",
          index: true,
  indexWidth:70,
          cellBtn: false,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn:false,
          keyId: "id",
          column: [
            {
              label: "衔接主题",
              width: 240,
              prop: "title",
              cell: true
            },
            {
              label: "发起时间",
              prop: "createTime",
              cell: true,
              formatter: function (row, value, label, column){
                if(value){
                  return value.split(' ')[0]
                }
                return value
              }
            },
            {
              label: "反馈部门",
              prop: "targetDeptName",
              cell: true
            },
            {
              label: "状态",
              width: 80,
              prop: "state",
              cell: true,
              formatter: function (row, value, label, column){
                switch (value) {
                  case '0':
                    return '催办';
                  case '1':
                    return '待反馈';
                  case '2':
                    return '退回';
                  case '3':
                    return '不采纳';
                  case '4':
                    return '已反馈';
                  case '5':
                    return '已采纳'
                }
              }
            },
          ]
        },
        tableLoading:false,
        projectForm: {
          opinion: '',
          hasOpinion: '1',
        },
        dialogVisible:false,
        detailData:[],
        fileIdstemp:[],
        title:'',
        files:[],
      }
    },
    methods:{
      // 课题详情跳转
      addPlanConnection(row){
        let src = `/addPlanConnection/detail/${this.$route.params.id}`;
        this.$router.push({
          path: src,
          query:{
            title:this.$route.query.title,
            orgName:this.$route.query.orgName,
          }
        })
      },
      currentChange(currentPage){
        var page = this.page;
        page.currentPage = currentPage;
        this.getResultList(page);
      },
      sizeChange(pageSize){
        var page = this.page;
        page.pageSize = pageSize;
        this.getResultList(page);
      },
      getResultList(page){
        opinionTagertList(Object.assign({
          current: page.currentPage,
          size: page.pageSize,
          relateId:this.$route.params.id,
          type:'6'
        })).then(response => {
          this.levyResultData = response.data.data.records;
          this.page.total = response.data.data.total;
        })
      },
      // // 发起课题征集跳转
      // addMaterialCollection(){
      //   let src = `/addMaterialCollection/detail/${this.$route.params.id}`;
      //   this.$router.push({
      //     path: src,
      //     query:{
      //       subjectTitle:this.$route.query.subjectTitle,
      //     }
      //   })
      // },
      // 课题详情跳转
      collectionFeedback(row){
        let src = `/collectionFeedback/detail/${row.fileTaskId}`;
        this.$router.push({
          path: src,
          query:{
            subjectId:row.subjectId,
            singleOrNot:'0',
            state:row.state,
          }
        })
      },
      urgentCollection(row){
        this.$confirm("确定向相应部门发起催办吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          urgentCollection(row.fileTaskId).then(response =>{
            if(response.data.code == 0){
              this.$notify({
                title: '成功',
                message: '催办成功',
                type: 'success',
                duration: 2000
              });
              this.$router.go(0);
            }
          })
        })
      },
      planConnectionFeedback(row){
          formOpinion(Object.assign({
            opinionId:row.opinionId,
            targetId:row.targetId,
          })).then(async response =>{
            var records = response.data.data.records[0];
            this.projectForm.contactName = records.contactName;
            this.projectForm.contactNumber = records.contactNumber;
            this.projectForm.opinion = records.opinion;
            if(records.fileIds!=null){
              if(records.fileIds.length!=0){
                this.files = await getFileTypeFiles(records.fileIds);
              }
            }
            if(records.hasOpinion!=null){
              if(records.hasOpinion){
                this.projectForm.hasOpinion = '1'
              }else {
                this.projectForm.hasOpinion = '0'
              }
            }
          });
        this.dialogVisible = true;
      },
    }
  }
</script>

<style lang="scss" scoped>

</style>
